#include "mpanel.h"
#include "mutil.h"

#include <QLayout>
#include <QSpacerItem>

MPanel::MPanel(QWidget *parent) :
    QWidget(parent)
{
    setLayout(new QHBoxLayout);

    btn_reset = new QPushButton(MUtil::getStr("btn_reset"));
    layout()->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
    btn_reset->setFixedSize(62, 38);
    layout()->addWidget(btn_reset);
    layout()->setAlignment(btn_reset, Qt::AlignBottom);

    btn_undo = new QPushButton(MUtil::getStr("btn_undo"));
    btn_undo->setFixedSize(81, 50);
    layout()->addWidget(btn_undo);
    layout()->setAlignment(btn_undo, Qt::AlignBottom);

    btn_ok = new QPushButton(MUtil::getStr("btn_ok"));
    btn_ok->setFixedSize(100, 62);
    layout()->addWidget(btn_ok);
    layout()->setAlignment(btn_ok, Qt::AlignBottom);

    btn_hint = new QPushButton(MUtil::getStr("btn_hint"));
    btn_hint->setFixedSize(81, 50);
    layout()->addWidget(btn_hint);
    layout()->setAlignment(btn_hint, Qt::AlignBottom);

    btn_quit = new QPushButton(MUtil::getStr("btn_quit"));
    btn_quit->setFixedSize(62, 38);
    layout()->addWidget(btn_quit);
    layout()->setAlignment(btn_quit, Qt::AlignBottom);

    layout()->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
    setUndoEnabled(false);
    setHintEnabled(false);
    setOKEnabled(true);

    connect(btn_reset, SIGNAL(clicked()), this, SLOT(resetClicked()));
    connect(btn_ok, SIGNAL(clicked()), this, SLOT(okClicked()));
    connect(btn_undo, SIGNAL(clicked()), this, SLOT(undoClicked()));
    connect(btn_hint, SIGNAL(clicked()), this, SLOT(hintClicked()));
    connect(btn_quit, SIGNAL(clicked()), this, SLOT(quitClicked()));
}

void MPanel::setUndoEnabled(bool value)
{
    btn_undo->setEnabled(value);
}

void MPanel::setOKEnabled(bool value)
{
    btn_ok->setEnabled(value);
}

void MPanel::setHintEnabled(bool value)
{
    btn_hint->setEnabled(value);
}

void MPanel::okClicked()
{
    emit ok();
}

void MPanel::undoClicked()
{
    emit undo();
}

void MPanel::hintClicked()
{
    emit hint();
}

void MPanel::resetClicked()
{
    emit reset();
}

void MPanel::quitClicked()
{
    std::exit(0);
}
